import {Net, WithFormUrlEncodedBody, WithoutToken} from "foundation"
import {RegisterAutoLogin as fRegisterAutoLogin} from "MVx"
import {IKnowModalOption} from "../utils/IKnowModalOption";

class Body {
  public userId:string;
  public token:string;
}

class Response {
  public body:Body = new Body();
}

export  function RegisterAutoLogin(net:Net) {
  fRegisterAutoLogin<Response>(net, '/customer/v2/login/code2Session', async ()=> {
    let ret= await Taro.login({});
    return {code:ret.code}
  }, Response, (ret):{uid:string, token:string} => {
    return {uid:ret.body.userId, token:ret.body.token}
  }, async err => {
    await Taro.showModal(IKnowModalOption("登录失败("+err.message+")"))
  },  WithFormUrlEncodedBody(), WithoutToken())
}
